package kpi.javatraining6.gnatiuk.tests;

import kpi.javatraining6.gnatiuk.src.teachingsystem.Difficulty;
import kpi.javatraining6.gnatiuk.src.tester.Questionnaire;
import kpi.javatraining6.gnatiuk.src.tester.question.Question;
import kpi.javatraining6.gnatiuk.src.tester.readers.QuestionsSAXParser;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

public class QuestionnaireTest {
    Questionnaire questionnaire;
    @Before
    public void setUp() throws Exception {
        questionnaire = new Questionnaire(new QuestionsSAXParser().parse("OOP.xml"));
    }

    @Test
    public void testNextNormalQuestion() throws Exception {
        Question question = questionnaire.nextQuestion(Difficulty.NORMAL);
        assertEquals("must be equal", Difficulty.NORMAL, question.getDifficulty());
    }

    @Test
    public void testNextEasyQuestion() throws Exception {
        Question question = questionnaire.nextQuestion(Difficulty.EASY);
        assertEquals("must be equal", Difficulty.EASY, question.getDifficulty());
    }

    @Test
    public void testNextHardQuestion() throws Exception {
        Question question = questionnaire.nextQuestion(Difficulty.HARD);
        assertEquals("must be equal", Difficulty.HARD, question.getDifficulty());
    }

    @Test
    public void testHasMoreQuestionsNormalDifficulty() throws Exception {
         assertTrue("must be true", questionnaire.hasMoreQuestions(Difficulty.NORMAL));
    }

    @Test
    public void testBack2() {
        Question question = questionnaire.nextQuestion(Difficulty.NORMAL);
        questionnaire.addToAnswered(question);
        questionnaire.putBack(question);
        Question nextQuestion = questionnaire.nextQuestion(Difficulty.NORMAL);
        assertEquals("must be equal", question, nextQuestion);
    }

    @Test
    public void testToString() {
        String rez = questionnaire.toString();
        assertEquals("must be String.class", String.class, rez.getClass());
    }
}
